package com.beiyou.config;

import com.beiyou.authority.AuthorityInterceptor;
import com.beiyou.authority.AuthorityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wzby
 * @Date: 2022/10/16 10:50
 */
@Import(AuthorityProperties.class)
@Order(Ordered.HIGHEST_PRECEDENCE)
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private AuthorityProperties authorityProperties;

    @Value("${beiyou.token.secret}")
    private  String  TOKEN_SECRET;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(new AuthorityInterceptor(TOKEN_SECRET))
               .addPathPatterns(authorityProperties.getPathPatterns())
               .excludePathPatterns(authorityProperties.getExcludePathPatterns());
    }
}
